package com.demo.application;

import cn.lingyangwl.framework.storage.base.manager.StorageManager;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;

/**
 * @author shenguangyang
 */
@Service
public class DemoStorageService {
    @Resource
    private StorageManager storageManager;

    public void upload(String filename) throws Exception {
        storageManager.uploadFile(Files.newInputStream(Paths.get(filename)), "image/jpeg", "test.jpg");
    }

    public void getFilePathList() {
        List<String> filePathList = storageManager.listFilePath("software-package/");
        for (String filePath : filePathList) {
            System.out.println(filePath);
        }
    }

    public InputStream getFile() {
        return storageManager.getFile("test.jpg");
    }

    public void deleteObjects() throws Exception {
        List<String> objectNames = new ArrayList<>();
        objectNames.add("test.jpg");
        objectNames.add("copy1.jpg");
        storageManager.deleteObjects(objectNames);
    }

    public void deleteObject() throws Exception {
        storageManager.deleteObject("copy2.jpg");
    }

    public void uploadDir() {
        storageManager.uploadDir("/code/my/springboot-demo/demo-ui/dist");
    }


}
